#!/bin/bash


#the installation needs more flexability - should work for debian based

#this is for convenience, not security
if [ $( whoami ) != "root" ]; then
  echo "ERROR: Installation must be run as root"
  exit -1
fi

#create a goog_pam directory in /etc/security if it doesn't exist
if [ ! -d /etc/security/goog_pam ]; then
  mkdir /etc/security/goog_pam
fi
if [ ! -d /etc/security/goog_pam ]; then
  echo "ERROR: unable to create directory in /etc/security/goog_pam"
  exit -1
fi

#copy main files over
cp ./pam_goog.so /lib/security/pam_goog.so

cp ./goog_pass_sock /etc/security/goog_pam/goog_pass_sock
cp ./goog_pam.conf /etc/security/goog_pam/goog_pam.conf
cp ./goog_access /etc/security/goog_pam/goog_access

#useradd goog_pam
/usr/sbin/useradd goog_pam

chown -R goog_pam:goog_pam /etc/security/goog_pam/
chmod 644  /lib/security/pam_goog.so
chmod 755  /etc/security/goog_pam/goog_pass_sock
chmod 600  /etc/security/goog_pam/goog_pam.conf
chmod 4555 /etc/security/goog_pam/goog_access

